<template>
  <div class="search-container" v-loading="loading">
    <el-form v-model="searchPage" inline="true" >
      <el-form-item  v-for="(item, index) in searchPage.items" :key="index" :label="item.cnname">
        <el-select  v-if="item.itemType === 'DICT'" v-model="item.value" :multiple = "item.mutSelect ==='checkBox'">
          <el-option  v-for="(itemChild, itemIndex) in item.dict" :key="itemIndex"  :label="itemChild.value" :value="itemChild.key" />
        </el-select>
        <el-input v-else-if="item.itemType !== 'DATE'" v-model="item.value"></el-input>
        <el-col :span="24" v-else>
          <el-form-item>
            <el-date-picker
              v-model="item.dateValue"
              type="date"
              label="Pick a date"
              placeholder="Pick a date"
              style="width: 100%"
            />
          </el-form-item>
        </el-col>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button @click="onReset">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
  <div class="data-container">
      <el-table :data="tableData" style="width: 100%">
      <el-table-column type="selection" width="55" />
      <el-table-column type="index" width="80" label="序号"/>
      <el-table-column prop="personType" label="人员类型" width="160" />
      <el-table-column prop="name" label="姓名" width="120" />
      <el-table-column prop="sex" label="性别" width="120">
        <template #default="scope">
          <el-select v-model="scope.row.sex" placeholder="请选择" disabled>
                <el-option label="男" value="0" />
                <el-option label="女" value="1" />
              </el-select>
        </template>
      </el-table-column>
      <el-table-column prop="cardType" label="证件类型" width="120" />
      <el-table-column prop="cardNo" label="证件号" width="160"></el-table-column>
      <el-table-column prop="birthDate" label="生日" width="120" />
      <el-table-column prop="nation" label="民族" width="120" />
      <el-table-column prop="marriageInfo" label="婚姻状况" width="120"></el-table-column>
      <el-table-column prop="politicalLandscape" label="政治面貌" width="200" />
      <el-table-column prop="country" label="国籍" width="160" />
      <el-table-column label="个人信息" width="140">
        <template #default="scope">
          <el-icon @click="showInfoExp(scope.row.id)"><InfoFilled /></el-icon>
        </template>
      </el-table-column>
      <el-table-column label="学习经历" width="140">
        <template #default="scope">
          <el-icon @click="showLearnExp(scope.row.id)"><InfoFilled /></el-icon>
        </template>
      </el-table-column>
      <el-table-column label="工作经历" width="140">
        <template #default="scope">
          <el-icon @click="showWorkExp(scope.row.id)"><InfoFilled /></el-icon>
        </template>
      </el-table-column>
      <el-table-column label="证件信息" width="140">
        <template #default="scope">
          <el-icon @click="showCertExp(scope.row.id)"><InfoFilled /></el-icon>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
    v-model:currentPage="searchPage.current"
    v-model:page-size="searchPage.pageSize"
    :page-sizes="[20, 50, 100]"
    layout="total, sizes, prev, pager, next, jumper"
    :total="tableDatas.total"
    hide-on-single-page=true
    @size-change="handleSizeChange"
    @current-change="handleCurrentChange"
  />
  <AppInfo :isShow="showDiag.info" @diaCancel="diaCnacel" :currentId="selectRowId"></AppInfo>
  <CertManage :isShow="showDiag.cert" @diaCancel="diaCnacel" :currentId="selectRowId"></CertManage>
  <LearnExp :isShow="showDiag.learn" @diaCancel="diaCnacel" :currentId="selectRowId"></LearnExp>
  <WorkExp :isShow="showDiag.work" @diaCancel="diaCnacel" :currentId="selectRowId"></WorkExp>
  </div>
</template>

<script setup>
import { ref, onActivated } from 'vue'
import { ElMessage } from 'element-plus'
import { list } from '@/api/common/common'
import { useI18n } from 'vue-i18n'
import { dateToString, dateToNext } from '@/utils/date'
import AppInfo from './appInfo/index.vue'
import CertManage from './certManage/index.vue'
import LearnExp from './learnExp/index.vue'
import WorkExp from './workExp/index.vue'

const tableDatas = ref({})

const selectRowId = ref(null)

const showDiag = ref({
  info: false,
  learn: false,
  work: false,
  cert: false
})

const diaCnacel = () => {
  showDiag.value = {
    info: false,
    learn: false,
    work: false,
    cert: false
  }
  selectRowId.value = null
}

const showInfoExp = id => {
  showDiag.value.info = true
  selectRowId.value = id
}

const showLearnExp = id => {
  showDiag.value.learn = true
  selectRowId.value = id
}

const showWorkExp = id => {
  showDiag.value.work = true
  selectRowId.value = id
}

const showCertExp = id => {
  showDiag.value.cert = true
  selectRowId.value = id
}

const tableData = ref([])

const i18n = useI18n()

const searchPage = ref({
  items: [
    {
      name: 'name',
      cnname: '姓名',
      itemType: 'STRING',
      sign: 'like',
      value: '',
      dateValue: ''
    },
    {
      name: 'createTime1',
      cnname: '开始时间',
      itemType: 'DATE',
      sign: '>=',
      value: dateToString(-7),
      dateValue: dateToNext(-7)
    },
    {
      name: 'createTime2',
      cnname: '结束时间',
      itemType: 'DATE',
      sign: '<=',
      value: dateToString(0),
      dateValue: dateToNext(0)
    }
  ],
  pageSize: 20,
  current: 1,
  sortBy: ['id']
})

const searchFunction = async () => {
  list(searchPage.value, 'recruit/admin').then(res => {
    tableData.value = res.content
    console.log(res)
    tableDatas.value.total = parseInt(res.totalElements)
    ElMessage.success('成功')
  }).catch(err => {
    ElMessage.success('失败' || err.message)
  })
}

onActivated(searchFunction())

const onSubmit = () => {
  searchFunction()
}

const onReset = () => {
  searchPage.value = {
    items: [
      {
        name: 'name',
        cnname: '姓名',
        itemType: 'STRING',
        sign: 'like',
        value: '',
        dateValue: ''
      },
      {
        name: 'createTime1',
        cnname: '开始时间',
        itemType: 'DATE',
        sign: '>=',
        value: dateToString(-7),
        dateValue: dateToNext(-7)
      },
      {
        name: 'createTime2',
        cnname: '结束时间',
        itemType: 'DATE',
        sign: '<=',
        value: dateToString(0),
        dateValue: dateToNext(0)
      }
    ],
    pageSize: 20,
    current: 1,
    sortBy: ['id']
  }
  // 处理查询
  searchFunction()
}

const handleSizeChange = pageSize => {
  searchPage.value.pageSize = pageSize
  // 执行查询操作
  searchFunction()
}

const handleCurrentChange = current => {
  searchPage.value.current = current
  // 执行查询操作
  searchFunction()
}

</script>

<style lang="scss" scoped>
.search-container {
  width: 100%;
  height: 100px;
}
</style>
